
from . import base_parser


class MyHTMLParser(base_parser.BaseHTMLParser):
    TITLE = '全国公共资源交易平台（广东省）'
    #HOST = 'http://bs.gdggzy.org.cn/osh-web/project/projectbulletin/bulletinList?queryType=1&tradeTypeId=GovernmentProcurement&tradeItemId=zf_res_bulletin'
    HOST =  'http://bs.gdggzy.org.cn/osh-web/project/projectbulletin/bulletinList?queryType=1&tradeTypeId=Construction&tradeItemId=gc_res_bulletin'

    headers= {
'Connection': 'keep-alive', 
'Cache-Control': 'max-age=0',
'Upgrade-Insecure-Requests': '1',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'en,zh-CN;q=0.9,zh;q=0.8',
'Cookie': 'Hm_lvt_e69ca51933e85f436518122b1647992e=1560226899; Hm_lpvt_e69ca51933e85f436518122b1647992e=1560468860; JSESSIONID=030C207CC2C5E28C0EECF69022390789; __jsluid=719838d7aa2ed00b5f7a9e7e81da67c9',
    }


    def __init__(self, host=None):
        
        if not host:
            host = self.HOST
        
        super(MyHTMLParser, self).__init__(host=host, headers=self.headers )
        self.host = host
        self.title = self.TITLE

        self.result_meta = {
            'len': 5,
            'href': ( 2, 'a', 'href' ),
            'title': ( 2, 'a', 'text' ),
            'city':  ( 3, 'td', 'text' ),
            'date':  ( 4, 'span','text' ),
        }
        
    def handle_result_href(self, href):
        return 'bs.gdggzy.org.cn' + href

    def handle_result_title(self, title):
        return title.strip()

